// pages/oneword/oneword.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        // width:wx.getSystemInfoSync().windowWidth,
        // height:wx.getSystemInfoSync().windowHeight,
        text: '',
        from: "",
        imageUrl: "https://cdn.pixabay.com/photo/2015/03/28/16/40/lake-696098_960_720.jpg",
        image:[
            "https://www4.bing.com//th?id=OHR.ValvestinoDam_ZH-CN8397604653_1920x1080.jpg&rf=LaDigue_1920x1080.jpg",
            "https://cdn.pixabay.com/photo/2013/07/18/20/26/sea-164989_960_720.jpg",
            "https://cdn.pixabay.com/photo/2015/03/28/16/40/lake-696098_960_720.jpg",
            "https://cdn.pixabay.com/photo/2013/04/04/12/34/mountains-100367_960_720.jpg",
            "https://cdn.pixabay.com/photo/2014/10/26/17/19/fisherman-504098_960_720.jpg",
            "https://cdn.pixabay.com/photo/2014/10/07/13/48/mountain-477832_960_720.jpg",
            "https://cdn.pixabay.com/photo/2015/12/01/20/28/road-1072821_960_720.jpg",
            "https://cdn.pixabay.com/photo/2014/09/10/00/59/mountains-440520_960_720.jpg",
            "https://cdn.pixabay.com/photo/2015/03/28/16/40/lake-696098_960_720.jpg"
        ]
    },
    getOneWord() {
        var that=this
        wx.request({
            url: 'https://v1.hitokoto.cn/',
            method: 'GET',
            success(res) {
                console.log(res)
                that.setData({
                    text: res.data.hitokoto,
                    from: res.data.from
                })
            }
        })
    },
    getBackgroundImage() {
        var that=this
        wx.request({
            url: 'https://v1.hitokoto.cn/',
            method: 'GET',
            success(res) {
                console.log(res)
                that.setData({
                    text: res.data.hitokoto,
                    from: res.data.from
                })
            }
        })
    },
    changeImage(){
        console.log(Math.floor(Math.random()*10))
        var index=Math.floor(Math.random()*10)+1
        this.setData({
            imageUrl:this.data.image[index]
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getOneWord()
        setInterval(() => {
            this.getOneWord()
            this.changeImage()
        }, 5000);
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})